package com.apop.accompany.bussiness.controller;

import com.apop.accompany.bussiness.model.vo.MenuVo;
import com.apop.accompany.bussiness.service.IMenuService;
import com.apop.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 登陆校验
 * @ClassName AuthController
 * @Author Jiayi Zheng
 * @Date 2022/1/4 17:31
 * @Description: todo
 * @Version V1.0
 */
@RestController
@RequestMapping("/v3pz/menu")
@Slf4j
public class MenuController {

    @Resource
    IMenuService iMenuService;

    /**
     * 可配置权限列表
     * @return
     */
    @GetMapping("/available_list")
    public Result availableList() {

        // 示例 JSON 字符串
        //String jsonString = "[{\"id\":1,\"label\":\"控制台\"},{\"id\":2,\"label\":\"权限管理\",\"children\":[{\"id\":4,\"label\":\"账号管理\",},{\"id\":5,\"label\":\"菜单管理\"}]},{\"id\":3,\"label\":\"DIDI陪诊\",\"children\":[{\"id\":6,\"label\":\"陪护管理\"},{\"id\":7,\"label\":\"订单管理\"}]}]";

        //JSON字符串转换成Java对象
        //List<Map> studentList = JSONObject.parseArray(jsonString, Map.class);

        List<MenuVo> listMenuVo = iMenuService.getAvailableMenuVo();
        log.info("listMenuVo {} ",listMenuVo);

        return Result.success(listMenuVo);
    }

    /**
     * 可配置权限列表
     * @return
     */
    @GetMapping("/menu_list")
    public Result menuList() {

        // 示例 JSON 字符串
        //String jsonString = "[{\"id\":1,\"label\":\"控制台\"},{\"id\":2,\"label\":\"权限管理\",\"children\":[{\"id\":4,\"label\":\"账号管理\",},{\"id\":5,\"label\":\"菜单管理\"}]},{\"id\":3,\"label\":\"DIDI陪诊\",\"children\":[{\"id\":6,\"label\":\"陪护管理\"},{\"id\":7,\"label\":\"订单管理\"}]}]";

        //JSON字符串转换成Java对象
        //List<Map> studentList = JSONObject.parseArray(jsonString, Map.class);

        List<MenuVo> listMenuVo = iMenuService.getAvailableMenuVo();
        log.info("listMenuVo {} ",listMenuVo);

        return Result.success(listMenuVo);
    }

    @PostMapping("/set")
    public Result setMenu(@RequestBody Map map) {
        log.info("收到请求 {}",map);
        return Result.success("操作成功");
    }



}
